/*
 * @Descripttion:
 * @version:
 * @Author: kl2018
 * @Date: 2019-07-20 14:17:14
 * @LastEditors: kl2018
 * @LastEditTime: 2020-08-18 09:43:12
 */
import React, { Component } from 'react';
import { Row, Col } from 'antd';
import { WeaTab, WeaLocaleProvider, WeaReportCard } from 'ecCom';
import { inject, observer } from 'mobx-react';
import { toJS } from 'mobx';
import { hashHistory } from 'react-router';

const { getLabel } = WeaLocaleProvider;

@inject('centerStore')
@observer
class OdocCenterTodoComp extends Component {
  componentDidMount() {
    const { centerStore } = this.props;
    centerStore.buildTodos();
    centerStore.buildTodoTabs();
  }

  render() {
    const { centerStore } = this.props;
    return (
      <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@y3toml`} id="rowTodos" className="wea-odoc-center-right-row">
        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@i8erjs`}>
          <WeaReportCard ecId={`${this && this.props && this.props.ecId || ''}_WeaReportCard@w0q0wm`}
            title={<span><span className="icon-coms-yellow-big"><i className="icon-coms-Planning-tasks" /></span>{getLabel(384728, '待办公文')}</span>}
            onMoreClick={this.jumpToTodo}
          >
            <WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@oqasny`}
              datas={centerStore.tabs}
              keyParam="viewcondition" // 主键
              countParam="groupid" // 数量
              selectedKey={centerStore.selectedTodoTab}
              onChange={centerStore.changeTodoTab}
            />
            {this.renderTodos()}
          </WeaReportCard>
        </Col>
      </Row>
    );
  }

  renderTodos() {
    const { centerStore } = this.props;
    let todos = toJS(centerStore.todos);
    let rows = [];

    if (todos.length > 0) {
      todos.map((data, index) => {
        rows.push(<Row ecId={`${this && this.props && this.props.ecId || ''}_Row@nwdyzk@${index}`}>
          <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@8d4070@${index}`}>
            <div className="right_c2">
              {/* <div className="right_c2_l">
               <p  class="wea-odoctype-labelp" title={data.odoctypename}>{data.odoctypename}</p>
              <p  title={data.odoctypename}>{data.odoctypename}</p>
            </div> */}
              <div className="right_c2_r">
                <div className="right_c2_r-top">
                  <p dangerouslySetInnerHTML={{ __html: data.showlink }} />
                </div>
                <div className="right_c2_r-bottom">
                  <a dangerouslySetInnerHTML={{ __html: data.creater }} />  &nbsp;&nbsp;
                {data.createdatetime}&nbsp;&nbsp;&nbsp;&nbsp;

              </div >
              </div>
            </div>
          </Col>
        </Row>);
      });
    }
    return (rows);
  }

  jumpToTodo() {
    // const { centerStore } = this.props;
    // const { selectedTodoTab } = centerStore
    // selectedTodoTab == '1' &&  hashHistory.push({pathname:"/main/offical/newTodo",query:{selectedTabKey:'0'}});
    // selectedTodoTab == '2' &&  hashHistory.push({pathname:"/main/offical/newTodo",query:{selectedTabKey:'0'}});
    // selectedTodoTab == '3' && hashHistory.push({ pathname: "/main/offical/newTodo", query: { selectedTabKey: '0' } });
    hashHistory.push({ pathname: '/main/offical/newTodo' });
  }
}

export default OdocCenterTodoComp;
